/*
 * @Author: thl t15945324431@163.com
 * @Date: 2023-12-12 16:22:58
 * @LastEditors: thl t15945324431@163.com
 * @LastEditTime: 2023-12-12 18:10:46
 * @FilePath: \cw_web\gl\src\views\privacySetting\userInfoEdit\component\editor.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { Component } from 'react';
import { Button, Form, Input, Space, Radio } from "antd";
import TheQuill from "../../../../components/TheQuill";
import TheUpload from '../../../../components/TheUpload';

class Editor extends Component {
    constructor(props) {
        super(props)
    }
    componentDidMount() {
        if (this.props.data) {
            this.formRef.setFieldsValue({ ...this.props.data })
            this.setNewsContent(this.props.data.alterNate)
        }
    }

    /**
     * @desc 设置新闻内容表单默认值
     * */
    setNewsContent = (data) => {
        console.log("data", data);
        this.formRef.setFieldsValue({ alterNate: data })
    }

    //图片上传回调
    getDetailsFileResult = value => {
        console.log(value)
        if (value.length && value[0] && value[0].response) {
            this.formRef.setFieldsValue({
                aboutUsDetailsImage: value[0].response.data
            })
        } else {
            this.formRef.setFieldsValue({
                aboutUsDetailsImage: ''
            })
        }
    }
    onFinish = (value) => {
        if (value.alterNate == "<p></p>") {
            return React.$message({
                type: 'info',
                content: `请输入内容`
            })
        }
        this.props.onFinish(value)
    }

    render() {
        const { btnLoading, dialogCancel, data, } = this.props
        let show = !!this.props.data.length
        return <Form
            ref={ref => {
                this.formRef = ref
            }}
            onFinish={this.onFinish}
        >
            <Form.Item name={'aboutUsTitle'} label={'发件人'}>
                {show && <Input maxLength={20} />}
                {!show && <span>{this.props.data.emailAddress}</span>}
            </Form.Item>
            <Form.Item label={'标题'} name={'title'} rules={[{ required: true, message: '请输入标题' }]}>
                <Input maxLength={64} />
            </Form.Item>
            <Form.Item name={'alterNate'}
                rules={[{ required: true, message: '请输入内容' }]}
                label={'内容'}>
                <TheQuill defaultValue={data.alterNate} setNewsContent={this.setNewsContent} />
            </Form.Item>
            <div className="p-text-align">
                <Space size="large">
                    <Button key="back" onClick={dialogCancel}>
                        取 消
                    </Button>
                    <Button type="primary" loading={btnLoading} htmlType="primary">
                        确 定
                    </Button>
                </Space>
            </div>
        </Form>
    }
}

export default Editor;